﻿function getParams() {
    var params = {};

    var companyName = $("input[name='companyName']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(companyName)) {
        params.companyName = companyName;
    }

    var orderNo = $("input[name='orderNo']").val();
    if (!FlashPay.Util.isNullOrEmptySpance(orderNo)) {
        params.orderNo = orderNo;
    }

    params.startTime = $("input[name='startTime']").val();
    params.endTime = $("input[name='endTime']").val();

    return params;
}

function doSearch() {

    emptyCompanyId();

    $("#transferCardRecord").datagrid({
        fit: false,
        loadMsg: '数据加载中，请稍后……',
        method: "get",
        border: true,
        url: '/Transfer/TransferCardRecord',
        queryParams: getParams(),
        pagination: true,
        pageSize: pageSize,
        pageList: [15, 30, 50, 100, 1000],
        height: $(window).height() - 70,
        singleSelect: true,
        rownumbers: true,
        showFooter: true,
        idField: 'orderNo',
        onLoadSuccess: function () {
            pageSize = $('#transferCardRecord').datagrid('options').pageSize;
        },
        frozenColumns: [[
            { field: 'orderNo', title: '订单号', width: 130, align: 'left' },
            { field: 'companyName', title: '公司名称', width: 100, align: 'left' },
            { field: 'withdrawalOrderNo', title: '中转单号', width: 180, align: 'left' },
            { field: 'bankName', title: '中转银行', width: 65, align: 'left' },
            { field: 'cardName', title: '中转名称', width: 65, align: 'left' },
            { field: 'cardNumber', title: '中转卡号', width: 120, align: 'left' }
        ]],
        columns: [[
            {
                field: 'withdrawalAmount',
                title: '中转金额',
                width: 65,
                align: 'right',
                formatter: function (val, row) {
                    return '<span class="bold">{0}</span>'.format(val);
                }
            },
            {
                field: 'transportDate',
                title: '中转时间',
                width: 120,
                align: 'left',
                formatter: function (val, item) {
                    if (item.transportStatus == 3 || item.transportStatus == 4) {
                        return FlashPay.Util.FormatDate(item.readDate);
                    } else {
                        return FlashPay.Util.FormatDate(val);
                    }
                }
            },
            {
                field: 'transportStatus',
                title: '中转结果',
                width: 200,
                align: 'left',
                formatter: function (val, item) {
                    /**
                     * 1、未付款
                     * 2、付款成功
                     * 3、付款失败
                     * 4、付款中
                     * 5、取消付款
                     * 6、第三方付款推送异常
                     * */
                    var result = '';
                    if (val == 1) {
                        result = '<span class="bold">未付款</span>';
                    } else if (val == 2) {
                        result = '<span class="green bold">付款成功{0}</span>'.format((item.transportFailInfo != null && item.transportFailInfo != "") ? " -" + item.transportFailInfo : "");
                    } else if (val == 3) {
                        result = '<span class="red bold">付款失败{0}</span>'.format((item.transportFailInfo != null && item.transportFailInfo != "") ? " -" + item.transportFailInfo : "");
                    } else if (val == 4) {
                        result = '<span class="bold">付款中</span>';
                        if (item.vmTimeDifference > 15) {
                            // <a class="btn btn-danger btn-xs" data-confirm="{0}<br> 确定要 <span class=red> 转失败</span> 该记录？" data-href="/Transfer/TransferCardRecordTurnFailed?orderNo={0}">转失败</a>
                            //result += ' <a class="btn btn-xs btn-warning" data-confirm="{0} <br>确定要<span class=orange>重新付款</span>该付款单？" data-href="/Transfer/RenewTransferCardRecord?orderNo={0}">重新付款</a>'.format(item.orderNo);
                        }
                        result += ' <a class="btn btn-warning btn-xs" onclick="return view(this)" data-href="/view/transfer/transfercardrecordreals.html?orderNo={0}" data-title="{0}-查询" data-width="400" data-height="130">查询</a>'.format(item.orderNo);
                    } else if (val == 5)  {
                        result = '<span class="bold">异常</span>';
                    }
                    return result;
                }
            },
            {
                field: 'noticeStatus',
                title: '通知状态',
                width: 125,
                align: 'left',
                formatter: function (val, item) {
                    /**
                     * 1、未通知
                     * 2、通知成功
                     * 3、通知失败
                     * 4、通知中
                     * */
                    var result = "";
                    if (val == 1) {
                        result = '<span class="bold">未通知</span>';
                    } else if (val == 2) {
                        result = '<span class="green bold">通知成功</span>';
                    } else if (val == 3) {
                        result = '<span class="red bold">通知失败</span>';
                        if (item.timeDifference > 6 && item.noticeTimes == 5) {
                            result += ' <a class="btn btn-xs btn-warning" data-confirm="{0} <br>确定要<span class=orange>重置</span>该付款单？" data-href="/Transfer/Reset?orderNo={0}">重置</a>'.format(item.orderNo);
                        }
                        
                    } else {
                        result = '<span class="bold">通知中</span>';
                    }
                    return result;
                }
            },
            { field: 'noticeTimes', title: '通知次数', width: 65, align: 'left' },
            {
                field: 'noticeLastDate',
                title: '通知时间',
                width: 120,
                align: 'left',
                formatter: function (val, row) {
                    return FlashPay.Util.FormatDate(val);
                }
            },
            { field: 'withdrawalAccountName', title: '客户姓名', width: 65, align: 'left' },
            { field: 'withdrawalBankName', title: '客户银行', width: 65, align: 'left' },
            { field: 'withdrawalCardNumber', title: '客户卡号', width: 150, align: 'left' },
            {
                field: 'createDate',
                title: '创建时间',
                width: 120,
                align: 'left',
                formatter: function (val, row) {
                    return FlashPay.Util.FormatDate(val);
                }
            }
        ]]
    })
}